import axios from 'axios'
import { config } from "@/config";

interface RequestOption {
    baseUrl: string,
    path: string,
    port: number
}

class WebData {
    baseUrl = ''
    path = ''
    port = 4000
    constructor(options: RequestOption) {

        this.baseUrl = options.baseUrl
        this.path = options.path
        this.port = options.port
    }
    getStaticData = async () => {
        const res = await axios.get(`${this.baseUrl}:${this.port}/${this.path}/staticData`)
        return res.data
    }

    queryDocument = async (content: string) => {
        const res = await axios.get(`${this.baseUrl}:${this.port}/${this.path}/queryDocument?content=${content}`)
        return res.data
    }

    getContextData = async (topic: string) => {
        const res = await axios.get(`${this.baseUrl}:${this.port}/${this.path}/context?topic=${topic}`)
        return res.data
    }
    getDocumentHomeData = async (path: string) => {
        const res = await axios.get(`${this.baseUrl}:${this.port}${path}`)
        return res.data
    }

    getHotData = async () => {
        const query = {
            condition: {
                isHot: true
            },
            limit: 4,
            skip: 0
        }
        const res = await axios.post(`${this.baseUrl}:${this.port}/${this.path}/getHot`, query)
        return res.data
    }

    getWeChatDoc = async (query:string) => {
        const res = await axios.get(`${this.baseUrl}:${this.port}/${this.path}/weichat?uri=${query}`)
        return res.data
    }

}



export const webData = new WebData({
    baseUrl: config.baseUrl,
    port: config.port,
    path: 'api'
})

